package C5.E1;

public class Example9 {
    public static final int TIMES = 100000;
    public static void main(String[] args) {
        Example9.testString();
        Example9.testStringBUffer();
        Example9.testStringBuilder();
    }
    public static void testString() {
        long startTime = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < TIMES; i++) {
            str  += "test";
        }
        long endTime = System.currentTimeMillis();
        System.out.println("String test usedtime: " + (endTime - startTime));
    }
    public static void testStringBUffer() {
        long startTime = System.currentTimeMillis();
        StringBuffer str = new StringBuffer();
        for (int i = 0; i < TIMES; i++) {
            str.append("test");
        }
        long endTime = System.currentTimeMillis();
        System.out.println("StringBuilder test usedtime: " + (endTime - startTime));
    }
    public static void testStringBuilder (){
        long startTime = System.currentTimeMillis();
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < TIMES; i++) {
            str.append("test");
        }
        long endTime = System.currentTimeMillis();
        System.out.println("StringBuilder test usedtime: " + (endTime - startTime));
    }
}
